package plugin;

import java.awt.Component;

import javax.swing.JFileChooser;
import javax.swing.JTextField;

import abbot.finder.BasicFinder;
import abbot.finder.ComponentFinder;
import abbot.finder.ComponentNotFoundException;
import abbot.finder.ComponentSearchException;
import abbot.finder.MultipleComponentsFoundException;
import abbot.finder.matchers.ClassMatcher;
import abbot.i18n.Strings;
import abbot.tester.ActionFailedException;
import abbot.tester.JFileChooserTester;
import abbot.tester.JTextComponentTester;

public class CrossJFileChooserTester extends JFileChooserTester{
	private ComponentFinder finder = BasicFinder.getDefault();
	public void actionSetFilename(Component c, String filename) {
		JTextField tf = null;
		try {
			tf = (JTextField)finder.find((JFileChooser)c, new ClassMatcher(JTextField.class));
		} catch (ComponentNotFoundException | MultipleComponentsFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		      
        if (tf == null) {
            String msg = Strings.get("未找到文件");
            throw new ActionFailedException(msg);
        }
        tf.setText(filename);
    }

}
